import java.util.Stack;

public class test2 {

    /*
    * || s.charAt(i) == ']' || s.charAt(i) == '}'*/
    public boolean isValid (String s) {
        // write code here
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{' ){
                stack.push(s.charAt(i));
            }else if(s.charAt(i) == ')' ){
                Character pop = stack.pop();
                if (pop != '(' ){
                    return false;
                }
            }else if(s.charAt(i) == ']'){
                Character pop = stack.pop();
                if (pop != '[' ){
                    return false;
                }
            }else if(s.charAt(i) == '}'){
                Character pop = stack.pop();
                if (pop != '{' ){
                    return false;
                }
            }
        }
        return true;
    }
}
